console.log('首页');

require('./home.less');

require('../../assets/css/index.less');

require('../../assets/fontss/iconfont.css');


let dom = require('../../utils/dom.js');
let https = require('../../utils/https.js')

let local = require('../../utils/local')


dom.isLogin();


import Swiper, { Pagination, Autoplay } from 'swiper';

import 'swiper/swiper-bundle.css'




dom.ready(function () {
    dom.boop('home')

    Swiper.use([Pagination, Autoplay]);
    new Swiper(".mySwiper", {
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: true,
        // autoplay: {

        //     delay: 2500,
        //     disableOnInteraction: false,
        // },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    });

    // console.log('表示当前页面的js代码----此处为功能代码');

    function getUserInfo() {
        https.get('/api/user/info', function (res) {
            // console.log(res);
            console.log(res);
            if (res.errno == 0) {
                dom.getEle('#btn').innerHTML = res.data.ranking;
                // dom.getEle('#btn1').innerHTML = res.data.clockCount;
                dom.getEle('#btn2').innerHTML = res.data.badges;
            }
        })
    }
    
    getUserInfo();
    
    
    
    // function getClock() {
    //     https.get('/api/user/clockInInfo', function (res) {
    //         if (res.errno == 0) {
    //             console.log(res.data);
    //             dom.getEle('#clockCountTxt').innerHTML = res.data.clockCount
    //             dom.getEle('#clockBtn').innerHTML = res.data.isClockIn ? "已经打卡" : "今日打卡"
    //         }
    //     })
    // }
    
    
    function getClock() {
        https.get('/api/user/clockInInfo', function (res) {
            //判定
            if (res.errno == 0) {
                console.log(res.data);
                //动态渲染指定数据到位置
                dom.getEle('#clockCountTxt').innerHTML = res.data.clockCount; //打卡天数
                // console.log(res.data.isClockIn); //false今天没有打卡,true已经打卡
                dom.getEle('#clockBtn').innerHTML = res.data.isClockIn ? "已经打卡" : "今日打卡"
    
            }
        })
    }
    getClock();
    
    
    dom.addEvent('#clockBtn', function () {
        console.log(111);
        https.post('/api/user/clockIn', {}, function (res) {
            
            if (res.errno == 0) {
                alert('打卡成功')
                getClock();
            } else {
                alert('打卡失败')
            }
        })
    })

})




// clockBtn.addEventListener('click', function () {
//     console.log(222);
// })


// local.set('name', '张三')

//console.log(local.get('name'));